#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
struct car{int d, v, a;}c[N];
int p[N], check[N];
signed main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        int n, m, l, V, num = 0;
        cin >> n >> m >> l >> V;
        for(int i = 1; i <= n; i++)  cin >> c[i].d >> c[i].v >> c[i].a;
        for(int i = 1; i <= m; i++)  cin >> p[i];
        for(int i = 1; i <= m; i++)  check[p[i]] = 1;
        for(int i = 1; i <= n; i++)
        {
            int dir = p[m] - c[i].d;
            if(dir < 0)  continue;
            else if(dir == 0)  if(c[i].v > V)  num++;
            else if(dir > 0)
            {
                if(c[i].a == 0)
                {
                    if(c[i].v > V)  num++;
                }
                else if(c[i].a < 0)
                {
                    if(c[i].v <= V)  continue;
                    else
                    {
                        int x = (V * V - c[i].v * c[i].v) / 2 / c[i].a, y;
                        for(int j = c[i].d; j < p[m]; j++)  if(check[j] == 1) y = j - c[i].d;
                        if(x > y) num++;
                    }
                }
                else if(c[i].a > 0)
                {
                    if(c[i].v >= V)  num++;
                    else
                    {
                        int x = (V * V - c[i].v * c[i].v) / 2 / c[i].a;
                        if(x < dir)  num++;
                    }
                }
            }
        }
        cout << num << "\n";
    }
    return 0;
}
